' Project must reference "Primavera Portfolio Management Open API Interface"
'
' This is a part of the Primavera Portfiolio Management API examples.
' Copyright 1998, 2020, Oracle and/or its affiliates. All Rights Reserved.
'
' This source code is only intended as a supplement to the
'   Primavera Portfolio Management Enterprise API
' electronic documentation provided with the product.
'
' This source code is compatible with Primavera Portfolio Management 20.0 

'*************************************************
' Set the 'Domains' value list to show only Items(1; 1.7), Portfolios, Gizmos(3;) , Wizards (; 3.14) , SubItems(;23.1023456789) and categories(;0).  Gizmos(3) will replace Applications(3)
'*************************************************

Public Sub psPortfoliosValueList_UpdateValues_Example_2()
    ' Login in to Portfolios
    Dim log As Object
    Set log = New psPortfoliosSecurity
    Dim token As String
    token = log.Login("admin", "Password", 10000)
    ' Note: Never code your Password in your program

    Dim vaValues() As Object
    ReDim Preserve vaValues(1 To 6)
    ' For VB.NET the last line should be rewritten as:
    '   ReDim Preserve vaValues(3)
    ' and array index should start at 0 instead of 1

    Set vaValues(1) = New psPortfoliosValueListValueInfo
    vaValues(1).ID=1
    vaValues(1).Text="Items"
    vaValues(1).Weight="1.7"

    Set vaValues(2) = New psPortfoliosValueListValueInfo
    vaValues(2).Text="Portfolios"

    Set vaValues(3) = New psPortfoliosValueListValueInfo
    vaValues(3).ID=3
    vaValues(3).Text="Gizmos"

    Set vaValues(4) = New psPortfoliosValueListValueInfo
    vaValues(4).Text="Wizards"
    vaValues(4).Weight="3.14"
	
	' WeightDouble property should be used to pass a double value(accepts precision up to 10 digits)
	' WeightDouble accepts only non-zero values.
	' If both WeightDouble and Weight is passed to the object, then WeightDouble value will be saved in the database if the value provided is non-zero value else Weight value will be saved in the database.
	Set vaValues(5) = New psPortfoliosValueListValueInfo
    vaValues(5).Text="SubItems"
    vaValues(5).WeightDouble="23.1023456789"
	
	' Weight property should be used if the value should be set to 0 as WeightDouble accepts only non-zero values
	Set vaValues(6) = New psPortfoliosValueListValueInfo
    vaValues(6).Text="categories"
    vaValues(6).Weight="0"
        
    Dim ValueListObj As Object
    Set ValueListObj = New psPortfoliosValueList
    
    ValueListObj.SetSecurity (token)
        
        Dim retVal 
        retVal = ValueListObj.UpdateValues( _
                             "Domains" _
                             , vaValues _
             )
    If (retVal = 0) Then
        MsgBox "Success !"
    Else
        Dim ErrorText As String
        ErrorText = ValueListObj.GetErrorString()
        MsgBox "Error " & retVal & "; " & ErrorText
        ' in a real system, the description is only displayed to support personnel, 
        ' not to the user
    End If


    ' Release security token (log out)
    log.ReleaseSecurityToken (token)
    
    Set ValueListObj = Nothing

End Sub


